package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.util.QiNiuUtil;

import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){
        Set<String> sdiffName = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);

        if (sdiffName!=null && sdiffName.size() >0){
            String[] deletestr = sdiffName.toArray(new String[]{});
            for (String s : deletestr) {
                System.out.println(s);
            }
            QiNiuUtil.removeFiles(deletestr);
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,deletestr);
        }
    }


}
